package com.fanbai.score.user.fragemnt;

/**
 * Created by acer on 2017/5/6.
 */

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.fanbai.score.R;
import com.fanbai.score.common.Utils.JsonUtils;
import com.fanbai.score.common.Utils.SPUtils;
import com.fanbai.score.common.Utils.ToastUtils;
import com.fanbai.score.common.activity.WebView_Activity;
import com.fanbai.score.common.base.BaseFragment;
import com.fanbai.score.common.http.CallBack;
import com.fanbai.score.user.activity.DaiQueRenJiFen_Activity;
import com.fanbai.score.user.activity.ElegantExchange_Activity;
import com.fanbai.score.user.activity.RedExchange_Activity;
import com.fanbai.score.user.bean.Scorestat_Bean;
import com.fanbai.score.user.http.UserScorea_RequestNet_Utils;

import org.w3c.dom.Text;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * A placeholder fragment containing a simple view.
 * 贵人币
 */
public class Elegant_Fragment extends BaseFragment {

    @BindView(R.id.userFragmentElegant_totalscore)
    TextView totalScore;//应该获取的总积分：567
    @BindView(R.id.userFragmentElegant_availablescore)
    TextView availableScore;//您拥有可兑换积分
    @BindView(R.id.userFragmentElegant_keDuiHuanBi)
    TextView keDuiHuanBi;//可兑换:123贵人币
    @BindView(R.id.userFragmentElegant_notavailable)
    TextView notavailable;//可以使用贵人币：567
    @BindView(R.id.userFragmentElegant_keDuiHuanHongBao)
    TextView kdhhb;//可兑换红包
    @BindView(R.id.userFragmentElegant_lingQain)
    TextView lingQian;//零钱

    @OnClick(R.id.userFragmentElegant_elegant)
    public void onClickElegant(){//兑换贵人币
        ctx.jumpToActivity(ElegantExchange_Activity.class);
    }
    @OnClick(R.id.userFragmentElegant_red)
    public void onClickRed(){//兑换红包
        ctx.jumpToActivity(RedExchange_Activity.class);
    }
    @OnClick(R.id.userFragmentElegant_dqrjf)
    public void onClickDRQJF(){
        ctx.jumpToActivity(DaiQueRenJiFen_Activity.class);
    }
    @OnClick(R.id.userFragmentElegant_buLing)
    public void onClickBL(){
        Bundle bundle = new Bundle();
        bundle.putString("url", "http://score.xinyou777.cn/customer/activity/replacementactivity.php");
        ctx.jumpToActivity(WebView_Activity.class, bundle);
    }
    @OnClick(R.id.userFragmentElegant_shuoMing)
    public void onClickSM(){
        Bundle bundle = new Bundle();
        bundle.putString("url", "http://score.xinyou777.cn/customer/html/guirenbi.html");
        ctx.jumpToActivity(WebView_Activity.class, bundle);
    }
    @OnClick(R.id.userFragmentElegant_tiXian)
    public void onClickTX(){
        ToastUtils.WarnImageToast(ctx, "暂未开放");
    }

    /**
     * The fragment argument representing the section number for this
     * fragment.
     */
    private static final String ARG_SECTION_NUMBER = "section_number";

    /**
     * Returns a new instance of this fragment for the given section
     * number.
     */
    public static Elegant_Fragment newInstance(int sectionNumber) {
        Elegant_Fragment fragment = new Elegant_Fragment();
        Bundle args = new Bundle();
        args.putInt(ARG_SECTION_NUMBER, sectionNumber);
        fragment.setArguments(args);
        return fragment;
    }

    public Elegant_Fragment() {
    }


    @Override
    protected int getLayoutID() {
        return R.layout.user_fragment_elegant;
    }

    @Override
    public String getTitleName() {
        return "贵人钱包";
    }

    @Override
    public void iniTitleLeft(ImageView imageView) {
    }

    @Override
    public void iniTitleRight(TextView tv) {

    }

    @Override
    protected void initView(View view) {
        titleBar.setVisibility(View.VISIBLE);
    }

    @Override
    protected void initData() {
        requestScorestat();
    }

    @Override
    protected void initListener() {

    }

    private void setData(Scorestat_Bean bean){

    }

    /**
     * 获取积分可兑换信息
     */
    private void requestScorestat(){
        ctx.showDialog();
        UserScorea_RequestNet_Utils.getScorestat(ctx, new CallBack<Scorestat_Bean>() {
            @Override
            public void onSuccess(String code, String msg, Scorestat_Bean bean) {
                totalScore.setText("应该获取的总积分："+bean.getTotalscore());
                availableScore.setText("您拥有可兑换积分："+bean.getAvailablescore());
                notavailable.setText("可以使用贵人币："+bean.getRechargablecoin());
                SPUtils.with(ctx).save(SPUtils.KEY_USER_TOTALSCORE, ""+bean.getTotalscore());
                SPUtils.with(ctx).save(SPUtils.KEY_USER_RECHARGABLECOIN, ""+bean.getRechargablecoin());
                getscoretotalinfo();
            }

            @Override
            public void onFailure(String code, String msg, String body) {
                ctx.hideDialog();
                ToastUtils.WarnImageToast(ctx, msg);
            }

            @Override
            public void onError(String code, String msg) {
                ctx.hideDialog();
                ToastUtils.WarnImageToast(ctx, msg);
            }
        });
    }

    private void getscoretotalinfo(){
        ctx.showDialog();
        UserScorea_RequestNet_Utils.getScoreTotalInfo(ctx, new CallBack<String>() {
            @Override
            public void onSuccess(String code, String msg, String s) {
                ctx.hideDialog();
                lingQian.setText("您的零钱："+JsonUtils.getString(s,"totalcash"));
                keDuiHuanBi.setText("可兑换："+JsonUtils.getString(s,"totalcoin")+"贵人币");
            }

            @Override
            public void onFailure(String code, String msg, String body) {
                ctx.hideDialog();
                ToastUtils.WarnImageToast(ctx, msg);
            }

            @Override
            public void onError(String code, String msg) {
                ctx.hideDialog();
                ToastUtils.WarnImageToast(ctx, msg);
            }
        });
    }
}
